package com.lancoo.answer.view.fragment.composition.continuation.sub;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.media.MediaPlayer;
import android.os.Environment;
import android.os.Looper;
import android.text.Editable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lancoo.answer.R;
import com.lancoo.answer.manager.MediaManager;
import com.lancoo.answer.model.bean.Item;
import com.lancoo.answer.model.bean.ItemAsk;
import com.lancoo.answer.model.bean.Type;
import com.lancoo.answer.util.DpUtils;
import com.lancoo.answer.util.EditTextInputUtil;
import com.lancoo.answer.util.NetWorkTools;
import com.lancoo.answer.util.RichTxtDealTuils;
import com.lancoo.answer.util.SoftInputUtils;
import com.lancoo.answer.util.WavAppendUtils;
import com.lancoo.answer.util.paperUtils.FragmentCommunicationUtils;
import com.lancoo.answer.view.fragment.composition.answer.CompositionAudioAnswerFragment;
import com.lancoo.answer.widget.WaveView;
import com.rxjava.rxlife.RxLife;
import com.stkouyu.LancooSpeechRecognitionManager;
import com.stkouyu.listener.OnLancooSpeechRecognitionListener;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by pengmi on 2022/5/26 14:39
 * Description:
 */
public class ContinuationAudioAnswerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private final String TAG_LOCAL_UPDATE="local_update";
    private static final String TAG_LOCAL_PAUSE="local_pause";
    private final String TAG_LOCAL_RELEASE="local_realse";
    private final Item item;
    private OnSubParagraphAnswerCallBack callBack;

    public ContinuationAudioAnswerAdapter(Item item) {
        this.item = item;
    }

    public void setCallBack(OnSubParagraphAnswerCallBack callBack) {
        this.callBack = callBack;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.ev_list_continuation_answer_audio_item_layout, parent, false);
        return new VH(inflate,callBack);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        VH vh= (VH) holder;
        vh.initData(item,position);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position, @NonNull List<Object> payloads) {
        super.onBindViewHolder(holder, position, payloads);
        if(payloads.contains(TAG_LOCAL_UPDATE)){
            Log.e("eee","去更新啦");
            VH vh= (VH) holder;
            vh.updateFocus();
        } else if(payloads.contains(TAG_LOCAL_PAUSE)){
            VH vh= (VH) holder;
            vh.pause();
        } else if(payloads.contains(TAG_LOCAL_RELEASE)){
            VH vh= (VH) holder;
            vh.release();
        }
    }

    @Override
    public int getItemCount() {
        return item.getItemAskList()==null?0:item.getItemAskList().size();
    }

    public static class VH extends RecyclerView.ViewHolder{

        private ItemAsk itemAsk;
        private final EditText editText;
        private final OnSubParagraphAnswerCallBack callBack;
        private int selecIndex=-1;
        private long subTime;
        private PopupWindow popupWindow;
        private WaveView waveView;
        private final String TAG="VH";
        private MediaManager mediaManager;

        @SuppressLint("ClickableViewAccessibility")
        public VH(@NonNull View itemView, OnSubParagraphAnswerCallBack callBack) {
            super(itemView);
            this.callBack=callBack;
            editText = itemView.findViewById(R.id.edittext);
            editText.setMinHeight(DpUtils.dip2px(editText.getContext(),30));
            if(editText.getText()!=null&& editText.getText().length()>0){
                editText.setSelection(editText.getText().length());
            }
            editText.setHint(R.string.ev_answer_input_continue_hint);
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) editText.getLayoutParams();
            layoutParams.weight=0;
            layoutParams.height=ViewGroup.LayoutParams.WRAP_CONTENT;
            editText.setLayoutParams(layoutParams);
            editText.requestLayout();
            SoftInputUtils.setEditTextInputSpace(editText);
            EditTextInputUtil.disableCopyAndPaste(editText);
            editText.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                    itemAsk.setFouceIndex(editText.getSelectionStart());
                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                }

                @Override
                public void afterTextChanged(Editable editable) {
                    setStuAnswerStr(editable.toString().trim());
                    updateAnswerCount();
                }
            });
            editText.setOnFocusChangeListener((v, hasFocus) -> {
                if(hasFocus){
                    int adapterPosition = getBindingAdapterPosition();
                    if(callBack==null||adapterPosition<0){
                        return;
                    }
                    selecIndex=editText.getSelectionStart();
                    callBack.onClickItemIndex(adapterPosition);
                }
            });
            editText.setOnClickListener(v -> {
                int adapterPosition = getBindingAdapterPosition();
                if(callBack==null||adapterPosition<0){
                    return;
                }
                callBack.onClickItemIndex(adapterPosition);
            });
            itemView.findViewById(R.id.img_microphone_recording).setOnTouchListener((v, event) -> {
                Context mContext=v.getContext();
                switch (event.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        subTime= System.currentTimeMillis();
                        subTime= System.currentTimeMillis();
                        startRecognition();
                        v.getParent().requestDisallowInterceptTouchEvent(true);
                        FragmentCommunicationUtils.testEventBus();
                        return true;
                    case MotionEvent.ACTION_UP:
                        if(NetWorkTools.isNetworkConnected(mContext)){
                            boolean isResult= System.currentTimeMillis()-subTime>=200;
                            stopRecognition(isResult);
                        }else{
                            stopRecognition(false);
                            Toast.makeText(mContext,"抱歉，当前网络不可用", Toast.LENGTH_SHORT).show();
                        }
                        return true;
                    case MotionEvent.ACTION_CANCEL:
                        return true;
                }
                return false;
            });
        }

        private void initData(Item item,int position){
            if(item.getItemAskList()==null){
                return;
            }
            itemAsk = item.getItemAskList().get(position);
            TextView tv_order = itemView.findViewById(R.id.tv_order);
            tv_order.setText(itemAsk.getAskTip());
            editText.setText(itemAsk.getStuAnswer());
            TextView tv_ask = itemView.findViewById(R.id.tv_ask);
            tv_ask.setVisibility(View.VISIBLE);
            RichTxtDealTuils.loadAskContent(tv_ask,itemAsk.getAsk()==null?"":itemAsk.getAsk());
            updateAnswerCount();
            selecIndex=itemAsk.getFouceIndex();
            updateMyAudioStyle();
            itemView.findViewById(R.id.tv_clear_answer).setOnClickListener(v -> {
                if(System.currentTimeMillis()-subTime<500){
                    return;
                }
                subTime=System.currentTimeMillis();
                showSwitchAnswerTypeDialog();
            });
            itemView.findViewById(R.id.tv_my_audio).setOnClickListener(v -> {
                if(System.currentTimeMillis()-subTime<500){
                    return;
                }
                subTime=System.currentTimeMillis();
                pauseOtherAudio();
                if(mediaManager==null||!mediaManager.isPlay()){
                    startPlayRecordSound();
                    showPlayState(true);
                }else{
                    showPlayState(false);
                    mediaManager.pause();
                }
            });

        }

        private void pauseOtherAudio(){
            if(getBindingAdapter()==null){
                return;
            }
            int itemCount = getBindingAdapter().getItemCount();
            int currentIndex=getBindingAdapterPosition();
            for (int i = 0; i < itemCount; i++) {
                if(i!=currentIndex){
                    getBindingAdapter().notifyItemChanged(i,ContinuationAudioAnswerAdapter.TAG_LOCAL_PAUSE);
                }
            }
        }

        private void updateFocus(){
            if(editText!=null){
                if(selecIndex!=-1){
                    editText.setSelection(Math.min(editText.getText().toString().length(), selecIndex));
                }
            }
        }


        /**
         * 统计作答个数
         */
        private void updateAnswerCount(){
            TextView tv_answerCount= itemView.findViewById(R.id.tv_answer_count);

            Observable.create((ObservableOnSubscribe<Integer>) emitter -> {
                        int count=0;
                        if(!TextUtils.isEmpty(itemAsk.getStuAnswer())){
                            String[] split = (itemAsk.getStuAnswer()+"")
                                    .replace("\n"," ")
                                    .split(" ");
                            count=split.length;
                            for (String str : split) {
                                if (str.isEmpty()) {
                                    count--;
                                }
                            }
                        }
                        emitter.onNext(Math.max(count,0));
                    })
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .as(RxLife.as(itemView,true))
                    .subscribe(integer -> {

                        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
                        spannableStringBuilder.append("Word Count:");
                        SpannableString spannableString = new SpannableString("" + integer);
                        spannableString.setSpan(new ForegroundColorSpan(0xff666666), 0, spannableString.length(),
                                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                        spannableStringBuilder.append(spannableString);
                        tv_answerCount.setText(spannableStringBuilder);
                    }, throwable -> {});

        }

        public void setStuAnswerStr(String answer){
            itemAsk.setStuAnswer(answer);
            editText.requestLayout();
            if(callBack!=null){
                callBack.updateAnswerCallBack();
            }
        }


        /**
         * 开始识别
         */
        private void startRecognition(){
            if (ActivityCompat.checkSelfPermission(itemView.getContext(), Manifest.permission.RECORD_AUDIO)
                    != PackageManager.PERMISSION_GRANTED) {
//            Toast.makeText(getApplicationContext(), "没有获取权限,请手动开启权限", Toast.LENGTH_SHORT).show();
                // 申请一个（或多个）权限，并提供用于回调返回的获取码（用户定义）
                String[] pressisionArray;
                try {
                    pressisionArray = new String[]{Manifest.permission.RECORD_AUDIO};
                    Log.e("eeee", "权限不足，请求响应");
                    ActivityCompat.requestPermissions((Activity) itemView.getContext() , pressisionArray, 100);//,Manifest.permission.READ_PHONE_STATE
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.e("eeee", "权限不足，error:"+e.toString());
                }
                return;
            }
            int adapterPosition = getBindingAdapterPosition();
            if(callBack!=null&&adapterPosition>=0){
                callBack.onClickItemIndex(adapterPosition);
            }
            showRecordPop();
            LancooSpeechRecognitionManager.getInstance(itemView.getContext())
                    .startSpeechRecognition(0, new OnLancooSpeechRecognitionListener() {
                        @Override
                        public void onSpeechRecognitionStart() {

                        }

                        @Override
                        public void onSpeechRecogniting(int vad_status, int sound_intensity) {
                            if(!itemView.isAttachedToWindow()){
                                return;
                            }
                            Observable.create((ObservableOnSubscribe<Integer>) emitter -> {
                                        emitter.onNext(sound_intensity);
                                    })
                                    .subscribeOn(Schedulers.io())
                                    .observeOn(AndroidSchedulers.mainThread())
                                    .as(RxLife.as(itemView))
                                    .subscribe(o -> {
                                        if(waveView!=null){
                                            waveView.setVisibility(View.VISIBLE);
                                            waveView.addData((short)sound_intensity);
                                        }
                                    }, throwable -> {});
                        }

                        @Override
                        public void onSpeechRecognitionEnd(String recognitionSentence, String url) {
                            appeandAudioFile(recognitionSentence,url);
                        }

                        @Override
                        public void onSpeechRecognitionError(String error) {

                        }
                    });
        }

        /**
         * 停止识别
         * @param isEnd 是否正常停止
         */
        private void stopRecognition(boolean isEnd){
            LancooSpeechRecognitionManager.getInstance(itemView.getContext()).stopSpeechRecognition(isEnd);
            if(popupWindow!=null&&popupWindow.isShowing()){
                popupWindow.dismiss();
            }
        }


        private void showRecordPop(){
            @SuppressLint("InflateParams") View inflater= LayoutInflater.from(itemView.getContext()).inflate(R.layout.ev_layout_pop_recording,null);
            popupWindow = new PopupWindow(inflater,
                    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            popupWindow.setFocusable(false);
            popupWindow.setOutsideTouchable(false);
            popupWindow.setBackgroundDrawable(new ColorDrawable());
            popupWindow.showAtLocation(itemView, Gravity.CENTER,0,0);
            waveView = inflater.findViewById(R.id.waveview);
        }

        /**
         * 拼接作答内容
         * @param appendContent content
         */
        private void appendAnswer(String appendContent,final String url){
            if(!TextUtils.isEmpty(appendContent)){
                boolean isEndEmpty=appendContent.endsWith(" ");
                String substring = appendContent.substring(0, 1);
                String s = substring.toUpperCase();
                appendContent=s+appendContent.substring(1,appendContent.length()-(isEndEmpty?1:0))+".";
            }
            Log.e(TAG,"appendAnswer:"+appendContent);
            Editable text = editText.getText();
            if(TextUtils.isEmpty(text)){
                editText.setText(appendContent);
                editText.setSelection(editText.getText().length());
            }else{
                int selectionStart = editText.getSelectionStart();
                if(selectionStart>=0&&selectionStart<text.length()){
                    text.insert(selectionStart,appendContent);
                    editText.setText(text);
                    editText.setSelection(selectionStart+appendContent.length());
                }else{
                    CharSequence charSequence = text.subSequence(text.length() - 1, text.length());
                    if (!TextUtils.equals(" ", charSequence)) {
                        text.append(" ");
                    }
                    text.append(appendContent);
                    editText.setSelection(text.length());
                }
            }
            itemAsk.setAudioPath(url);
            updateMyAudioStyle();

        }


        /**
         * 音频识别成功后，先拼接，再上传，再回显
         * @param appendContent content
         * @param tempUrl url
         */
        private void appeandAudioFile(String appendContent,String tempUrl){
            if(TextUtils.isEmpty(itemAsk.getAudioPath())){//如果本地存储的文件为空，就直接上传录音文件
                itemAsk.setAudioPath(tempUrl);
                appendAnswer(appendContent,tempUrl);
            }else{

                Observable.create((ObservableOnSubscribe<Boolean>) emitter -> {
                            String tempPath=System.currentTimeMillis()+".wav";
                            String tempRecordFilePath = getTempRecordFilePath();
                            File newFile=new File(tempRecordFilePath,tempPath);//newFile是新的temp文件，用于上传时的临时文件
                            if(!newFile.exists()){
                                boolean newFile1 = newFile.createNewFile();
                                Log.e(TAG,"下一步进行临时文件拷贝"+newFile1);
                            }
                            Log.e(TAG,"下一步进行临时文件拷贝");
                            //把已保存的本地录音音频copy到temp文件中进行合成，再上传
                            FileInputStream fileInputStream=new FileInputStream(itemAsk.getAudioPath());
                            FileOutputStream fileOutputStream=new FileOutputStream(newFile);
                            byte[] buffer=new byte[1024];
                            int byteRead;
                            while (-1!=(byteRead =fileInputStream.read(buffer))){
                                fileOutputStream.write(buffer,0,byteRead);
                            }
                            fileInputStream.close();
                            fileOutputStream.flush();
                            fileOutputStream.close();

                            File oldFile=new File(newFile.getPath());
                            File mergeFile=new File(tempUrl);
                            boolean isSuccess= WavAppendUtils.appendWav(oldFile,mergeFile);
                            emitter.onNext(isSuccess);
                        })
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .as(RxLife.as(itemView))
                        .subscribe(aBoolean -> {
                            if (aBoolean) {
                                itemAsk.setAudioPath(tempUrl);
                                Log.e(TAG,"next");
                                appendAnswer(appendContent,tempUrl);
                            }
                            Log.e(TAG, "isSuccess" + aBoolean);
                        }, throwable -> {});
            }
        }

        private String getTempRecordFilePath(){
            File targetDir = new File(Environment.getExternalStorageDirectory(),
                    "Android/data/" + itemView.getContext().getApplicationInfo().packageName + "/files/record/klg/temp");
            if (!targetDir.exists()) {
                boolean isCreate=targetDir.mkdirs();
                if(isCreate){
                    Log.e("eeee","路径创建成功");
                }
            }
            return targetDir.getPath();
        }

        private void updateMyAudioStyle(){
            TextView tv_myAudio = itemView.findViewById(R.id.tv_my_audio);
            View view_end = itemView.findViewById(R.id.view_end);
            TextView tv_clearAnswer = itemView.findViewById(R.id.tv_clear_answer);
            View view_start = itemView.findViewById(R.id.view_start);
            if(TextUtils.isEmpty(itemAsk.getAudioPath())){
                tv_myAudio.setEnabled(false);
                tv_myAudio.setTextColor(0xff999999);
                tv_myAudio.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ev_vector_horn_gray,0,0,0);
                view_end.setBackgroundResource(R.drawable.ev_shape_audio_answer_f7_bg);

                tv_clearAnswer.setEnabled(false);
                tv_clearAnswer.setTextColor(0xff999999);
                tv_clearAnswer.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ev_vector_delet_answer_gray,0,0,0);
                view_start.setBackgroundResource(R.drawable.ev_shape_audio_answer_f7_bg);
            }else{
                tv_myAudio.setEnabled(true);
                tv_myAudio.setTextColor(0xff0099ff);
                tv_myAudio.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ev_vector_horn_0,0,0,0);
                view_end.setBackgroundResource(R.drawable.ev_shape_audio_answer_bg);
                tv_clearAnswer.setEnabled(true);
                tv_clearAnswer.setTextColor(0xff0099ff);
                tv_clearAnswer.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ev_vector_delet_answer,0,0,0);
                view_start.setBackgroundResource(R.drawable.ev_shape_audio_answer_bg);
            }
        }


        private void showSwitchAnswerTypeDialog(){
            View inflate=LayoutInflater.from(itemView.getContext()).inflate(R.layout.ev_dialog_switch_answer_type,null);
            AlertDialog.Builder builder=new AlertDialog.Builder(itemView.getContext(),R.style.ev_dialogStyle);
            builder.setView(inflate);
            final AlertDialog alertDialog = builder.create();
            alertDialog.show();
            Window window = alertDialog.getWindow();
            if(window==null){
                return;
            }
            WindowManager.LayoutParams attributes = window.getAttributes();
            int width =itemView.getContext().getResources().getDisplayMetrics().widthPixels;
            int px280 = (int)itemView.getContext().getResources().getDisplayMetrics().density*280;
            attributes.width=Math.min(width*280/375,px280);
            alertDialog.getWindow().setAttributes(attributes);
            TextView tv_content=inflate.findViewById(R.id.tv_content);
            tv_content.setText("您确认清空录音吗？");
            TextView tv_cancel=inflate.findViewById(R.id.tv_cancel);
            tv_cancel.setText("取消");
            inflate.findViewById(R.id.tv_cancel).setOnClickListener(v -> {
                if(System.currentTimeMillis()-subTime<200){
                    return;
                }
                subTime=System.currentTimeMillis();
                alertDialog.dismiss();
            });
            inflate.findViewById(R.id.tv_sure).setOnClickListener(v -> {
                if(System.currentTimeMillis()-subTime<200){
                    return;
                }
                subTime=System.currentTimeMillis();
                alertDialog.dismiss();
                setStuAnswerStr("");
                itemAsk.setAudioPath("");
                pause();
                updateMyAudioStyle();
                if(mediaManager!=null){
                    mediaManager.stop();
                }
            });

        }

        public void pause(){
            Log.e(TAG,"pause");
            if(mediaManager!=null){
                mediaManager.pause();
            }
            if (mDisposable!=null) {
                mDisposable.dispose();
            }
            showPlayState(false);
        }

        public void release(){
            if(mediaManager!=null){
                mediaManager.release();
            }
            if (mDisposable!=null) {
                mDisposable.dispose();
            }
        }


        private void startPlayRecordSound(){
            if(mediaManager==null){
                mediaManager=new MediaManager(itemView.getContext());
            }

            String url = itemAsk.getAudioPath();
            if(mediaManager.isPrepared()){
                mediaManager.start();
                return;
            }
            mediaManager.setUpMedia(url, new MediaManager.OnPlayListener() {
                @Override
                public void onComplete() {
                    showPlayState(false);
                }

                @Override
                public void onStartError() {
                    showPlayState(false);
                }

                @Override
                public void onPausePlay() {

                }

                @Override
                public void onSourceError() {
                    showPlayState(false);
                }

                @Override
                public void onStopPlay() {

                }

                @Override
                public void onPrepare() {
                    if(mediaManager!=null){
                        mediaManager.start();
                    }
                }

                @Override
                public void onBufferingUpdate(MediaPlayer mp, int percent) {
                    Log.e(TAG,"onBufferingUpdate:"+percent);
                }
            });
        }


        private int times=0;
        private Disposable mDisposable;

        private void showPlayState(boolean isPlaying){
            if( Looper.myLooper() != Looper.getMainLooper()){
                return;
            }
            TextView tv_myAudio = itemView.findViewById(R.id.tv_my_audio);
            if(tv_myAudio!=null&&tv_myAudio.isEnabled()){
                if(isPlaying){
                    times=0;
                    Observable.interval(500, TimeUnit.MILLISECONDS)
                            .observeOn(AndroidSchedulers.mainThread())
                            .as(RxLife.as(itemView,true))
                            .subscribe(new Observer<Long>() {

                                @Override
                                public void onSubscribe(@io.reactivex.annotations.NonNull Disposable disposable) {
                                    mDisposable = disposable;
                                }

                                @Override
                                public void onNext(@io.reactivex.annotations.NonNull Long number) {
                                    times++;
                                    switch (times%3){
                                        case 1:
                                            tv_myAudio.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ev_vector_horn_1,0,0,0);
                                            break;
                                        case 2:
                                            tv_myAudio.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ev_vector_horn_2,0,0,0);
                                            break;
                                        default:
                                            tv_myAudio.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ev_vector_horn_0,0,0,0);
                                    }
                                }

                                @Override

                                public void onError(@io.reactivex.annotations.NonNull Throwable e) {

                                }

                                @Override

                                public void onComplete() {
                                }

                            });
                }else{
                    if (mDisposable != null){
                        mDisposable.dispose();
                    }
                    tv_myAudio.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ev_vector_horn_0,0,0,0);
                }
            }else{
                updateMyAudioStyle();
            }
        }

    }

    public void localUpdate(int position){
        notifyItemChanged(position,TAG_LOCAL_UPDATE);
    }


    public static abstract class OnSubParagraphAnswerCallBack {

        public void updateAnswerCallBack(){}

        public void onClickItemIndex(int itemIndex){}
    }


    public void pauseMedia(){
        if(item.getItemAskList()==null){
            return;
        }
        for (int i = 0; i < item.getItemAskList().size(); i++) {
            notifyItemChanged(i,TAG_LOCAL_PAUSE);
        }

    }

    public void releaseMedia(){
        if(item.getItemAskList()==null){
            return;
        }
        for (int i = 0; i < item.getItemAskList().size(); i++) {
            notifyItemChanged(i,TAG_LOCAL_RELEASE);
        }
    }


}
